<?php


namespace app\backend\service;

use app\common\model\CountAdv;
use app\common\RootCountService;

class CountAdvService extends RootCountService
{

    public function lists(array $params)
    {
        return $this->getData((new CountAdv()), $params);
    }

    public function editRowField(array $params)
    {
        $data = [];
        $row  = CountAdv::where('id', $params['id'])->field("user_num")->find();
        if (empty($row)) {
            return ['msg' => "数据异常"];
        }
        if (!empty($params['adv_income'])) {
            $data['adv_income']       = $params['adv_income'];
            $data['agv_devote_money'] = $row['user_num'] > 0 ? bcdiv($params['adv_income'], $row['user_num'], 3) : 0;
        }
        if (count($data) > 0) {
            $res = CountAdv::update($data, ['id' => $params['id']]);
            if ($res) {
                return ['msg' => '修改成功'];
            }
        }
        return ['msg' => '修改失败'];
    }
}